package com.cci.kangdao.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.annotation.MapperScan;

import java.util.List;
import java.util.Map;

//ccec诊断维修信息
@MapperScan
public interface CCECDiagnoseRepairMsgTDao {


    int insertSelective(Map<String, Object> map);

    int updateByPrimaryKeySelective(Map<String, Object> map);


    @Select("select b.ID as CCECDiagnoseRepairMsId,a.ESN as WorkOrderESN,c.WarrantyStartDate as WorkOrderWarrantyStartDate,c.EngineStartDatePicUrl as WorkOrderEngineStartDatePicUrl\n" +
            ",b.EngineIsMatching, case when b.EngineIsMatching = 0 then (select em.ESN from EngineMsg em where em.id = b.RealEngineMsgId) else '' end as RealESN,b.RealEngineMsgId, \n" +
            "case when b.EngineIsMatching = 0 then (select em.WarrantyStartDate from EngineMsg em where em.id = b.RealEngineMsgId) else '' end as RealESNWarrantyStartDate, \n" +
            "case when b.EngineIsMatching = 0 then (select em.EngineStartDatePicUrl from EngineMsg em where em.id = b.RealEngineMsgId) else '' end as RealESNEngineStartDatePicUrl, \n" +
            "b.IsWarrantyDate,a.CustomerName,a.CustomerPhone,b.AffirmFaultSymptom,b.RepairsMsgOrther,b.DiagnoseStepResult, d.DInt as IntCCECConfirmDuty,d.DValue as ValueCCECConfirmDuty,\n" +
            "ISNULL(b.IsBeginRepair,-1) as IsBeginRepair,c.engineType,a.CustomerComplaint,b.PartInfo,b.FaultCodeInfos,b.FaultExcludeStepResult,ISNULL(a.ServiceInitPlan,'') as ServiceInitPlan from WorkOrder_T a\n" +
            "left join CCECDiagnoseRepairMsg_T b on a.ID = b.OrderId \n" +
            "left join EngineMsg c on a.ESN = c.ESN\n" +
            "left join Dictionaries_T d on d.DInt = b.ConfirmDuty and DTableName = 'CCECConfirmDuty'\n" +
            "where a.ID = #{orderId}")
    Map<String,Object> getDiagnosiResultByOrderId(@Param("orderId")long orderId);


    @Select("select top 1 * from CCECDiagnoseRepairMsg_T where OrderId = #{orderId}")
    Map<String,Object> getDiagnosiResultMsgByOrderId(@Param("orderId")long orderId);
    
    int updateIsBeginRepairByOrderId(@Param("orderId")long orderId,@Param("updator")Long updator,@Param("updateTime")String updateTime);


}
